home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hapyhols / reqfiles / animate.sx
Encoding:
Text File  |  1996-05-21  |  1.0 KB  |  48 lines  |  [TEXT/ttxt]

  1. in module HolidayModule
  2.  
  3. class Animation (TwoDShape)
  4. instance variables
  5.     animationClock
  6.     series
  7.     cell
  8. end
  9.  
  10. method start self {class Animation} ->
  11. (
  12.     self.animationClock.rate := 1
  13. )
  14.  
  15. method stop self {class Animation} ->
  16. (
  17.     self.animationClock.rate := 0
  18. )
  19.  
  20. -- Called at each tick of the animation clock.
  21. -- Change current cell to the next cell in the series.
  22. method tick self {class Animation} clk ->
  23. (
  24.     -- Change to the appropriate cell
  25.     self.boundary := self.series[self.cell]
  26.     
  27.     -- Get the next cell. Wrap around if at the end.
  28.     self.cell := ((mod self.cell self.series.size) as Integer) + 1
  29. )
  30.  
  31. method init self {class Animation} #rest args \
  32.                                    #key series:(#(new Oval x2:100 y2:100)) \
  33.                                         scale:(5) ->
  34. (
  35.     apply nextMethod self boundary:(series[1]) fill:defaultBrush args
  36.     
  37.     self.series := series
  38.     self.cell := 1
  39.     
  40.     local animationClock := (new Clock scale:scale)
  41.     addPeriodicCallBack animationClock (clk -> tick self clk) animationClock #() 1
  42.     animationClock.rate := 0
  43.     self.animationClock := animationClock
  44.     self
  45. )
  46.  
  47.  
  48.